package c.c.b.a.b.a.c;

import c.c.b.a.b.a.e;
import c.c.b.a.b.b;
import c.c.b.a.b.j;
import c.c.b.a.b.s;
import c.c.b.a.b.w;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Proxy.Type;
import java.net.ProxySelector;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/* compiled from: RouteSelector */
public final class f {
    public final b a;
    public final d b;
    public final j c;
    public final s d;
    public List<Proxy> e = Collections.emptyList();
    public int f;
    public List<InetSocketAddress> g = Collections.emptyList();
    public final List<c.c.b.a.b.f> h = new ArrayList();

    /* compiled from: RouteSelector */
    public static final class a {
        public final List<c.c.b.a.b.f> a;
        public int b = 0;

        public a(List<c.c.b.a.b.f> list) {
            this.a = list;
        }

        public boolean a() {
            return this.b < this.a.size();
        }
    }

    public f(b bVar, d dVar, j jVar, s sVar) {
        this.a = bVar;
        this.b = dVar;
        this.c = jVar;
        this.d = sVar;
        w wVar = bVar.a;
        Proxy proxy = bVar.h;
        if (proxy != null) {
            this.e = Collections.singletonList(proxy);
        } else {
            List select = bVar.g.select(wVar.f());
            if (select == null || select.isEmpty()) {
                select = e.l(Proxy.NO_PROXY);
            } else {
                select = e.k(select);
            }
            this.e = select;
        }
        this.f = 0;
    }

    public void a(c.c.b.a.b.f fVar, IOException iOException) {
        if (fVar.b.type() != Type.DIRECT) {
            b bVar = this.a;
            ProxySelector proxySelector = bVar.g;
            if (proxySelector != null) {
                proxySelector.connectFailed(bVar.a.f(), fVar.b.address(), iOException);
            }
        }
        d dVar = this.b;
        synchronized (dVar) {
            dVar.a.add(fVar);
        }
    }

    public boolean b() {
        return c() || !this.h.isEmpty();
    }

    public final boolean c() {
        return this.f < this.e.size();
    }
}
